package org.dromara.system.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.domain.bo.SysFaultFeedbackEnAuditBo;
import org.dromara.system.domain.bo.SysFaultFeedbackEnQueryBo;
import org.dromara.system.domain.vo.SysFaultFeedbackEnVo;
import org.dromara.system.service.ISysFaultFeedbackEnService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * English Fault Feedback Management Controller
 *
 * @author system
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/fault-feedback-en")
public class SysFaultFeedbackEnController extends BaseController {

    private final ISysFaultFeedbackEnService feedbackService;

    /**
     * Query feedback list (management)
     */
    @SaCheckPermission("system:faultFeedbackEn:list")
    @GetMapping("/list")
    public TableDataInfo<SysFaultFeedbackEnVo> list(
        SysFaultFeedbackEnQueryBo queryBo, PageQuery pageQuery) {
        return feedbackService.queryPageList(queryBo, pageQuery);
    }

    /**
     * Get feedback detail
     */
    @SaCheckPermission("system:faultFeedbackEn:query")
    @GetMapping("/{feedbackId}")
    public R<SysFaultFeedbackEnVo> getInfo(
        @NotNull(message = "Feedback ID cannot be empty") @PathVariable Long feedbackId) {
        SysFaultFeedbackEnVo vo = feedbackService.queryById(feedbackId);
        return R.ok(vo);
    }

    /**
     * Audit feedback
     */
    @SaCheckPermission("system:faultFeedbackEn:audit")
    @Log(title = "English Fault Feedback Audit", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public R<Void> audit(@Validated @RequestBody SysFaultFeedbackEnAuditBo auditBo) {
        boolean result = feedbackService.auditFeedback(auditBo);
        return toAjax(result);
    }

    /**
     * Export feedback list
     */
    @SaCheckPermission("system:faultFeedbackEn:export")
    @Log(title = "English Fault Feedback", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(SysFaultFeedbackEnQueryBo queryBo, HttpServletResponse response) {
        List<SysFaultFeedbackEnVo> list = feedbackService.queryList(queryBo);
        ExcelUtil.exportExcel(list, "Fault Feedback (English)", SysFaultFeedbackEnVo.class, response);
    }
}


